package com.cx.service.impl;

import com.cx.mapper.RecommendMapper;
import com.cx.pojo.Recommend;
import com.cx.pojo.RecommendExample;
import com.cx.service.RecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class RecommendServiceImpl implements RecommendService {
    @Autowired
    RecommendMapper recommendMapper;

    @Override
    public int insert(Recommend recommend) {
        int rows = recommendMapper.insertSelective(recommend);
        return rows;
    }

    @Override
    public int updateById(Integer recId, Recommend recommend) {
        RecommendExample recommendExample = new RecommendExample();
        RecommendExample.Criteria criteria = recommendExample.createCriteria();
        criteria.andRecIdEqualTo(recId);
        int rows = recommendMapper.updateByExample(recommend,recommendExample);
        return rows;
    }

    @Override
    public int deleteById(Integer recId) {
        int rows = recommendMapper.deleteByPrimaryKey(recId);

        //RecommendExample recommendExample = new RecommendExample();
        //RecommendExample.Criteria criteria = recommendExample.createCriteria();
        //criteria.andRecIdEqualTo(recId);
        //int rows = recommendMapper.deleteByExample(recommendExample);
        return rows;
    }

    @Override
    public List<Recommend> selectByRecCity(String recCity) {
        RecommendExample recommendExample = new RecommendExample();
        RecommendExample.Criteria criteria = recommendExample.createCriteria();
        criteria.andRecCityEqualTo(recCity);
        List<Recommend> recommend = recommendMapper.selectByExample(recommendExample);
        return recommend;
    }

    @Override
    public List<Recommend> selectByRecDate(Date recDate) {
        RecommendExample recommendExample = new RecommendExample();
        RecommendExample.Criteria criteria = recommendExample.createCriteria();
        criteria.andRecDateEqualTo(recDate);
        List<Recommend> recommend = recommendMapper.selectByExample(recommendExample);
        return recommend;
    }

    @Override
    public List<Recommend> selectAll() {
        List<Recommend> recommends = recommendMapper.selectAll();
        return recommends;
    }
}
